package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.SmallVideosService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {
    @Autowired
    private SmallVideosService smallVideosService;

    @PostMapping
    public ResponseEntity saveVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        smallVideosService.saveVideos(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    @GetMapping
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1") int page,
                                         @RequestParam(defaultValue = "5") int pagesize) {
        PageResult pr = smallVideosService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    //视频点赞
    @PostMapping("/{id}/like")
    public ResponseEntity videoLike(@PathVariable ObjectId id) {
        Integer count = smallVideosService.videoLike(id);
        return ResponseEntity.ok(count);
    }

    //视频取消点赞
    @PostMapping("/{id}/dislike")
    public ResponseEntity videoDisLike(@PathVariable ObjectId id) {
        Integer count = smallVideosService.videoDisLike(id);
        return ResponseEntity.ok(count);
    }

    //视频关注
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity videoUserFocus(@PathVariable Long uid){
        smallVideosService.videoUserFocus(uid);
        return ResponseEntity.ok(null);
    }

    //视频取消关注
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity videoUserUnFocus(@PathVariable Long uid){
        smallVideosService.videoUserUnFocus(uid);
        return ResponseEntity.ok(null);
    }
}
